<!-- UserController.php-->
<?php 
	require 'Admin/Model/FoodModel.php';
	require 'Controller.php';
	class foodController extends Controller{
		function listfoods(){
			$model = new FoodModel();
			$data = $model->getfoodList();
			//转向用户列表页面
			include 'Admin/View/food/foodlist.php';
		}

		function foodform(){
			//转向添加用户页面
			include 'Admin/View/food/foodform.php';
		}

		function foodedit(){
			$id = $_GET['id'];
			$model = new FoodModel();
			$result = $model->getUserByID($id);
			include 'Admin/View/food/foodedit.php';
		}

		function foodsearch(){
			$foodname = $_POST['foodname'];
			$model = new foodModel();
			$data = $model->getfoodinfor($foodname);
			include dirname(dirname(__FILE__)).'/View/food/search.php';
		}

		function foodupdate(){
			$id = $_GET['id'];
			$model = new FoodModel();
			$result = $model->Updatefood($id);
			if($result){
				echo '修改成功'.'<a href="admin.php?c=food&m=listfoods">如果没有跳转，请点这里跳转</a>';
				header("refresh:3;admin.php?c=food&m=listfoods = admin.php?c=food&m=listfoods"); 	
			}else{
				echo '失败';
			}
		}

		function delfood(){
			$id = $_GET['id'];
			$model = new FoodModel();
			$result = $model->Delfood($id);
			if($result){
				echo '删除成功'.'<a href="admin.php?c=food&m=listfoods">如果没有跳转，请点这里跳转</a>';
				header("refresh:3;admin.php?c=food&m=listfoods = admin.php?c=food&m=listfoods"); 
			}else{
				echo '删除失败';
			}
		}

		function addfood(){
			//获取表单的数据
			//调用model中的addUser方法，添加到数据库中
			//var_dump($_POST);
			$data = $_POST;
			$model = new FoodModel();
			$result = $model->addfood($data);
			//如果成功，输出，转到列表页面
			if($result){
				echo '添加成功'.'<a href="admin.php?c=food&m=listfoods">如果没有跳转，请点这里跳转</a>';
				header("refresh:3;admin.php?c=food&m=listfoods = admin.php?c=food&m=listfoods"); 
			}else{
				echo '失败';
			}

		}
	}
 ?>